#include "QpcrLog.h"

QpcrLog::QpcrLog(QString ID)
{
    shiyanID = ID;
    UpdateFile up;
    Logger& logger = Logger::instance();    //初始化
    logger.setLoggingLevel(QsLogging::InfoLevel);  //设置写入等级

    const QString sLogPath(up.getDir(shiyanID)); //设置写入文件

    //该文件可被拆分，当大小超10M时被拆分，最多5个旧文件（超过则自动删除最旧的）
    DestinationPtr fileDestination(DestinationFactory::MakeFileDestination(sLogPath, EnableLogRotation, MaxSizeBytes(1024*1024*10), MaxOldLogCount(5)));
    logger.addDestination(fileDestination);

}

QpcrLog::~QpcrLog()
{
    QsLogging::Logger::destroyInstance();   //释放
}


void QpcrLog::write(QString data)
{
    QLOG_INFO()<<data;
    qDebug()<<"写入完毕";
}



/*!
 * \brief 初始化logs文件夹以及log.txt文件
 *
 * Detail here!!!
 */
void QpcrLog::init()
{
    UpdateFile up;

    //创建txt文件
    up.createFile(shiyanID);

}

/*!
 * \brief 释放logger对象
 *
 * Detail here!!!
 */
void QpcrLog::release()
{
    QsLogging::Logger::destroyInstance();   //释放
}


